$(function() {
	$("#save").bind("click", function() {
		var messagecode = $("#messagecode").val();
		if (messagecode == "" || messagecode == '请输入验证码') {
			myalert("验证码不能为空");
			return false;
		}
		var newpasswd = $("#newpasswd").val();
		if (newpasswd == "" || newpasswd == '请输入新密码') {
			myalert("新密码不能为空");
			return false;
		}
		var newpwResult = checkPasswd(newpasswd);
		if (!newpwResult.result) {
			myalert(newpwResult.msg);
			return false;
		}
		var repwResult = checkRePasswd($("#newpasswd").val(), $("#renewpasswd").val());
		if (!repwResult.result) {
			myalert(repwResult.msg);
			return false;
		}
		showLoading();
		$.ajax({
			type : "post",
			url : appPath + "/setting/editpaypwsubmit.html",
			data : {
				loginname : $("#loginname").val(),
				messagecode : $("#messagecode").val(),
				paypw : $.md5($("#newpasswd").val() + $("#key1").val()),
				key1 : $("#key1").val(),
				token : $.cookie("token")
			},
			success : function(result) {
				hideLoading();
				myalert(result.msg, function() {
					if (result.code == '1') {
						gotoHtml('/setting/account.htm');
					} else if (result.code == -1){
						window.location = appPath + "/member/login.htm";
					}
				});
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				hideLoading();
	            myalert("系统异常，请稍后再试");
	        }
		});
	});

	var InterValObj;// timer变量，控制时间
	var curCount = 60;// 当前剩余秒数
	$("#getcode").bind("click", function() {
		showLoading();
		$.ajax({
			type : "get",
			url : appPath + "/member/sendCodeByMobile.html",
			data : {
				tid : new Date().getTime(),
				loginname : $("#loginname").val()
			},
			success : function(result) {
				hideLoading();
				myalert(result.msg);
				if (result.code == '1') {
					curCount = 60;
					InterValObj = window.setInterval(setRemainTime, 1000);
				} else if (result.code == '-2') {
					curCount = result.second;
					InterValObj = window.setInterval(setRemainTime, 1000);
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				hideLoading();
	            myalert("系统异常，请稍后再试");
	        }
		});
	});
	// 验证码有效期倒计时
	function setRemainTime() {
		if (curCount == 0) {
			window.clearInterval(InterValObj);// 停止计时器
		} else {
			curCount--;
		}
	}
})